<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>个人主页</title>
		<style>
			body {
				font-family: Arial, sans-serif;
				display: flex;
				justify-content: center;
				align-items: center;
				height: 100vh;
				margin: 0;
				background-color: #f4f4f4;
			}

			.profile-card {
				text-align: center;
				background: white;
				padding: 20px;
				border-radius: 10px;
				box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
			}

			.avatar {
				width: 100px;
				height: 100px;
				border-radius: 50%;
				object-fit: cover;
				margin-bottom: 10px;
			}

			.nickname {
				font-size: 1.5em;
				margin-bottom: 20px;
			}

			.signature {
				width: 90%;
				padding: 10px;
				border: 1px solid #ccc;
				border-radius: 5px;
				margin-bottom: 10px;
				resize: none;
			}

			.button {
				padding: 10px 20px;
				background-color: #007bff;
				color: white;
				border: none;
				border-radius: 5px;
				cursor: pointer;
			}

			.button:hover {
				background-color: #0056b3;
			}

			.buttonO {
				background-color: #aa0000;
			}

			.buttonO:hover {
				background-color: #7c0000;
			}
		</style>
	</head>
	<body>

		<div class="profile-card">
			<img src="{{ .avatar_url }}" alt="用户头像" class="avatar">
			<p class="nickname">{{ .nickname }}</p>
			<textarea id="signature" class="signature" placeholder="点击这里输入或修改个性签名...">{{ .signature }}</textarea>
			<input type="hidden" name="userid" value="{{ .UserID }}" id="userid">
			<button class="button" onclick="updateSignature()">更新签名</button>
			<button class="button buttonO" onclick="exit()">退出登陆</button>
		</div>

		<script>
			function exit() {
				fetch('/api/exit', {
						method: 'POST',

					})
					.then(response => {
						return response.json();
					})
					.then(data => {
						if (data.success) {
							alert('已退出！');
							window.location.reload(true);
						}
					})
			}

			function updateSignature() {
				var userid = document.getElementById('userid').value;
				var signature = document.getElementById('signature').value;

				fetch('/api/updateSignature', { // 请替换为实际的API端点
						method: 'POST',
						headers: {
							'Content-Type': 'application/json'
						},
						body: JSON.stringify({
							signature: signature,
							userid: userid
						})
					})
					.then(response => {
						return response.json();
					})
					.then(data => {
						if (data.success) {
							alert('您的个性签名已成功更新！');
						} else {
							alert('更新失败，请重试。');
						}
					})
					.catch(error => {
						console.error('Error:', error);
						alert('发生错误，请稍后再试。');
					});
			}
		</script>

	</body>
</html>